package com.unisci.android.dialog;

import com.unisci.android.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CreateProjectDialog extends Dialog implements OnClickListener {
	private Button mSureButton;
	private Button mCancelButton;
	private EditText mNameEditText;
	private onCreateProjectListener mListener;

	public CreateProjectDialog(Context context) {
		super(context);
		initViews();
		setTitle("设置名称");
	}

	private void initViews() {
		View view = LayoutInflater.from(getContext()).inflate(
				R.layout.dialog_create_project, null);
		mSureButton = (Button) view.findViewById(R.id.btn_dialog_ok);
		mCancelButton = (Button) view.findViewById(R.id.btn_dialog_cancel);
		mNameEditText = (EditText) view.findViewById(R.id.et_dialog_name);
		mSureButton.setOnClickListener(this);
		mCancelButton.setOnClickListener(this);
		super.setContentView(view);
	}

	public void setOnCreateProjectListener(onCreateProjectListener listener) {
		mListener = listener;
	}

	public interface onCreateProjectListener {
		public void onCreateProject(String name);
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		// clear edittext content
		mNameEditText.setText("");
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.btn_dialog_ok) {
			mListener.onCreateProject(mNameEditText.getEditableText()
					.toString());
			// dismiss();
		} else if (v.getId() == R.id.btn_dialog_cancel) {
			dismiss();
		}
	}
}
